using System;
using LegoBotPrima;
using LegoBotPrimaAbstractions;
using NUnit.Framework;

namespace LegoBotPrimaTests
{
    [TestFixture]
    public class MathUtil_Fixture
    {
        [Test]
        public void Can_Find_Angles_Differrence_From_350_to_10()
        {
            var difference = MathUtil.AnglesDiff(350, 10);
            Assert.That(difference, Is.EqualTo(20));
        }

        [Test]
        public void Can_Find_Angles_Differrence_From_10_to_350()
        {
            var difference = MathUtil.AnglesDiff(10, 350);
            Assert.That(difference, Is.EqualTo(-20));
        }

        [Test]
        public void Can_Find_Angles_Differrence_From_350_to_0()
        {
            var difference = MathUtil.AnglesDiff(350, 0);
            Assert.That(difference, Is.EqualTo(10));
        }

        [Test]
        public void Can_Find_Angles_Differrence_From_0_to_350()
        {
            var difference = MathUtil.AnglesDiff(0, 350);
            Assert.That(difference, Is.EqualTo(-10));
        }

        [Test]
        public void Can_Find_Angles_Differrence_From_10_to_45()
        {
            var difference = MathUtil.AnglesDiff(10, 45);
            Assert.That(difference, Is.EqualTo(35));
        }

        [Test]
        public void Can_Find_Angles_Differrence_From_45_to_10()
        {
            var difference = MathUtil.AnglesDiff(45, 10);
            Assert.That(difference, Is.EqualTo(-35));
        }

        [Test]
        public void Can_Find_Angles_Differrence_From_10_to_190()
        {
            var difference = MathUtil.AnglesDiff(10, 190);
            Assert.That(difference, Is.EqualTo(180));
        }

        [Test]
        public void Can_Find_Angles_Differrence_From_190_to_10()
        {
            var difference = MathUtil.AnglesDiff(190, 10);
            Assert.That(difference, Is.EqualTo(-180));
        }
        

        [Test]
        public void RandomBooleanWithProbability_Function_Works_As_Expected()
        {
            var trueValues = 0;
            const int all = 10000;
            const double probability = 0.37;
            const double allowed_shift = 0.06;
            for (var i = 0; i < all; i++)
            {
                if (MathUtil.RandomBooleanWithProbability(probability))
                {
                    trueValues++;
                }
            }

            var resultProbability = trueValues/(double)all;

            Assert.That(resultProbability, Is.InRange(probability - allowed_shift, probability + allowed_shift), "The probability shifts too much from the expected value");

            //Console.WriteLine(resultProbability);
        }
        
    }
}